package com.hl.sfzy.controller.myController;

import com.hl.sfzy.entity.my.MyAnswer;
import com.hl.sfzy.service.myService.MyAnswerService;
import com.hl.sfzy.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("api/my/answer")
public class MyAnswerController {
    @Autowired
    private MyAnswerService myAnswerService;

    @GetMapping("getAnswers")
    public R answer(@RequestParam int userId, @RequestParam int pageNo, @RequestParam int pageSize) {
        try {
            List<MyAnswer> myAnswers = myAnswerService.myAnswerList(userId, pageNo, pageSize);
            int total = myAnswerService.countMyAnswers(userId);

            Map<String, Object> result = new HashMap<>();
            result.put("list", myAnswers);
            result.put("total", total);

            return R.success(result);
        } catch (Exception e) {
            return R.failure("查询失败: " + e.getMessage());
        }
    }
}